package com.yss.reportworld.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yss.common.core.utils.easyexecl.EasyExeclUtil;
import com.yss.common.core.utils.uuid.IdUtils;
import com.yss.reportworld.service.ISqlScriptService;
import com.yss.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yss.common.logger.annotation.Log;
import com.yss.common.logger.enums.BusinessType;
import com.yss.common.security.annotation.RequiresPermissions;
import com.yss.reportworld.domain.DemandBugInfo;
import com.yss.reportworld.service.IDemandBugInfoService;
import com.yss.common.core.web.controller.BaseController;
import com.yss.common.core.web.domain.AjaxResult;
import com.yss.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 需求BUG信息Controller
 *
 * @author yss
 * @date 2023-03-27
 */
@RestController
@RequestMapping("/demandBugInfo")
public class DemandBugInfoController extends BaseController {
    @Autowired
    private IDemandBugInfoService demandBugInfoService;
    @Autowired
    private ISqlScriptService sqlScriptService;

    /**
     * 查询需求BUG信息列表
     */
    @RequiresPermissions("reportworld:demandbuginfo:list")
    @GetMapping("/list")
    public TableDataInfo list(DemandBugInfo demandBugInfo) {
        startPage();
        List<DemandBugInfo> list = demandBugInfoService.selectDemandBugInfoList(demandBugInfo);
        return getDataTable(list);
    }

    /**
     * 初始化 加载
     */
    @RequiresPermissions("reportworld:demandbuginfo:list")
    @Log(title = "表明细信息", businessType = BusinessType.OTHER)
    @PostMapping("/init")
    public AjaxResult init(@RequestBody DemandBugInfo demandBugInfo) {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("hisVersions", sqlScriptService.getReductionVersion(false));
        return ajax;
    }

    /**
     * 导出需求BUG信息列表
     */
    @RequiresPermissions("reportworld:demandbuginfo:export")
    @Log(title = "需求BUG信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemandBugInfo demandBugInfo) {
        List<DemandBugInfo> list = demandBugInfoService.selectDemandBugInfoList(demandBugInfo);
        EasyExeclUtil.export(response, list, DemandBugInfo.class);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException {
        EasyExeclUtil.export(response, null, DemandBugInfo.class);
    }

    /**
     * 获取需求BUG信息详细信息
     */
    @RequiresPermissions("reportworld:demandbuginfo:query")
    @PostMapping(value = "/getInfo")
    public AjaxResult getInfo(@RequestBody DemandBugInfo demandBugInfo) {
        return success(demandBugInfoService.getDemandBugInfo(demandBugInfo));
    }

    /**
     * 新增需求BUG信息
     */
    @RequiresPermissions("reportworld:demandbuginfo:add")
    @Log(title = "需求BUG信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DemandBugInfo demandBugInfo) {
        String id = IdUtils.fastSimpleUUID();
        demandBugInfo.setId(id);
        demandBugInfoService.insertDemandBugInfo(demandBugInfo);
        return success(id);
    }

    /**
     * 修改需求BUG信息
     */
    @RequiresPermissions("reportworld:demandbuginfo:edit")
    @Log(title = "需求BUG信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DemandBugInfo demandBugInfo) {
        demandBugInfoService.editDemandBugInfo(demandBugInfo);
        return success();
    }

    /**
     * 删除需求BUG信息
     */
    @RequiresPermissions("reportworld:demandbuginfo:remove")
    @Log(title = "需求BUG信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody DemandBugInfo demandBugInfo) {
        demandBugInfoService.deleteDemandBugInfo(demandBugInfo);
        return success();
    }

    /**
     * 读取需求BUG信息
     */
    @RequiresPermissions("reportworld:demandbuginfo:import")
    @Log(title = "需求BUG信息", businessType = BusinessType.IMPORT)
    @PostMapping("/readDemandBugInfo")
    public AjaxResult readDemandBugInfo(MultipartFile file, boolean updateSupport, String hisVersion) throws Exception {
        return success(demandBugInfoService.readDemandBugInfo(file, updateSupport, hisVersion));
    }
}
